package org.example.server.search.mapstruct;

import org.example.api.goods.category.response.CategorySummaryResponse;
import org.example.api.goods.goods.response.GoodsParamResponse;
import org.example.api.goods.goods.response.GoodsSkuResponse;
import org.example.api.goods.goods.response.GoodsTagResponse;
import org.example.api.search.controller.response.GoodsDocSummeryResponse;
import org.example.frw.api.base.response.PageResponse;
import org.example.server.search.bo.GoodsDocSummaryBo;
import org.example.server.search.doc.GoodsDOC;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.List;

@Mapper(componentModel = "spring")
public interface GoodsDocConverter {
  /**
   * 转换实例
   */
  GoodsDocConverter INSTANCE = Mappers.getMapper(GoodsDocConverter.class);

  @Mapping(target = "createTime", source = "createTime", qualifiedByName = "dateToLong")
  @Mapping(target = "updateTime", source = "updateTime", qualifiedByName = "dateToLong")
  GoodsDOC.Category toCategoryDOC(CategorySummaryResponse category);

  @Mapping(target = "createTime", source = "createTime", qualifiedByName = "dateToLong")
  @Mapping(target = "updateTime", source = "updateTime", qualifiedByName = "dateToLong")
  GoodsDOC.Sku toSkuDOC(GoodsSkuResponse response);

  List<GoodsDOC.Sku> toSkuDOC(List<GoodsSkuResponse> skus);

  @Mapping(target = "createTime", source = "createTime", qualifiedByName = "dateToLong")
  @Mapping(target = "updateTime", source = "updateTime", qualifiedByName = "dateToLong")
  GoodsDOC.Param toParamDOC(GoodsParamResponse response);

  List<GoodsDOC.Param> toParamDOC(List<GoodsParamResponse> params);

  @Mapping(target = "createTime", source = "createTime", qualifiedByName = "dateToLong")
  @Mapping(target = "updateTime", source = "updateTime", qualifiedByName = "dateToLong")
  GoodsDOC.Tag toTagDOC(GoodsTagResponse response);

  List<GoodsDOC.Tag> toTagDOC(List<GoodsTagResponse> tags);

  @Named("dateToLong")
  default Long dateToLong(Date date) {
    return date != null ? date.getTime() : null;
  }
  GoodsDocSummaryBo toGoodsDocSummaryBo(GoodsDOC source);

  List<GoodsDocSummeryResponse> toGoodsDocSummeryResponse(List<GoodsDocSummaryBo> goodsDocSummaryBos);

  PageResponse<GoodsDocSummeryResponse> toPageGoodsDocSummeryResponse(PageResponse<GoodsDocSummaryBo> goodsDocSummaryBoPageResponse);
}
